<template>
  <view class="bgf">
    <view class="pa-10" style="border-radius: 10rpx">
      <view class="disFlxJS pt-10 px-15">
        <view>自动通过审证审方</view>
        <u-switch v-model="info.autoApPrescription" :activeValue="1" :inactiveValue="0" @change="handEdit"></u-switch>
      </view>
      <view class="pt-5 pb-10 px-15 linh-24 color9 borderB">
        开启后，所有需您审核的症方将自动通过，并在处方上显示您的签名。
      </view>
      <u-cell size="large" title="审核医生签名" :border="false" :value="info.prescriptionSign ? '已设置,去修改' : '未设置'" isLink url="/expertIdentity/prescription/signature"></u-cell>
      <view v-if="info.prescriptionSign" class="mx-15" style="border: dashed 1px #e2e2e2;">
        <image :src="info.prescriptionSign" style="width:100%;height: auto;" mode="widthFix" />
      </view>
    </view>
  </view>
</template>

<script>
import expApi from '@/api/expertIdentity.js';

export default {
	data() {
		return {
      info: {
        autoApPrescription: 0,
        prescriptionSign: ""
      }
		};
	},
  onShow() {
    this.getData()
  },
  methods: {
    async getData() {
      const { data } = await expApi.getSetUp();
      this.info = data;
    },
    handEdit(e) {
      if(e === 1 && !this.info.prescriptionSign){
        uni.showToast({
          title: '需先设置签名才再开启',
          icon: 'none'
        })
        this.info.autoApPrescription = 0;
        return
      }
      expApi.setSetUp({type: 1, value: this.info.autoApPrescription}).then(_r =>{
        let toast = this.info.autoApPrescription === 0 ? { title: '已关闭自动通过',icon: 'none'} : {title: '已开启自动通过'}
        uni.showToast(toast);
      }).catch(err=>{
        this.info.autoApPrescription = this.info.autoApPrescription === 0 ? 1 : 0;
        uni.showToast({
          title: '开启自动通过失败,请重试',
          icon: 'none'
        })
      })
    }
  }
};
</script>

<style lang="scss" scoped></style>
